Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

페이지 기능: 로그인 이후 토큰 인증에 따라 로그인 만료, 로그인 연장 처리 #182

Merged
merged 13 commits into from
Feb 20, 2024

Conversation

seoye0ng
Copy link
Collaborator

해당 사항 (중복 선택)

  • FEAT : 새로운 기능 추가 및 개선
  • TEST : 테스트 추가 및 리팩토링
  • FIX : 버그 수정
  • REFACTOR : 결과의 변경 없이 코드의 구조를 재조정
  • STYLE : 코드 스타일에 관련된 변경 사항
  • DOCS : 코드가 아닌 문서를 수정한 경우
  • REMOVE : 파일을 삭제하는 작업만 수행
  • RENAME : 파일 또는 폴더명을 수정하거나 위치(경로)를 변경
  • CHORE : 패키지 매니저 설정, 코드 수정 없이 설정 변경(eslint) 등 기타 사항

설명

Key Changes

  1. 로그인 토큰 인증 post 요청 response type 정의
  2. 로그인 토큰 인증 post 요청 쿼리 훅 작성
  3. 15분마다 토큰 인증 post 요청하는 커스텀 훅 작성
  4. 로그인 토큰 인증이 새로고침 시에도 동작하도록 최상위 컴포넌트에서 실행
  5. 토큰 인증 msw 작성 및 로그인, 토큰인증 mock data 작성
  6. 로그아웃 커스텀 훅 제작
  7. axios interceptor에서 토큰이 쿠키에 저장되어 있다면 가져오도록 설정

How it Works

To Reviewers

아직 api가 완성되지 않아 mock data 작성해서 진행했습니다.

@seoye0ng seoye0ng added ✨ Feature 기능 개발 🔨 Refactor 코드 리팩토링 ✅ Test test 관련(storybook, jest...) labels Feb 20, 2024
@seoye0ng seoye0ng self-assigned this Feb 20, 2024
Copy link

vercel bot commented Feb 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
f1-wash-pedia-fe ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 20, 2024 8:02am

@seoye0ng seoye0ng linked an issue Feb 20, 2024 that may be closed by this pull request
5 tasks
@seoye0ng seoye0ng requested a review from bottlewook February 20, 2024 04:00
@seoye0ng seoye0ng changed the title 페이지 기능: 로그인 이후 로그인 만료, 로그인 연장 처리 페이지 기능: 로그인 이후 토큰 인증 후 로그인 만료, 로그인 연장 처리 Feb 20, 2024
@seoye0ng seoye0ng changed the title 페이지 기능: 로그인 이후 토큰 인증 후 로그인 만료, 로그인 연장 처리 페이지 기능: 로그인 이후 토큰 인증에 따라 로그인 만료, 로그인 연장 처리 Feb 20, 2024
Copy link
Collaborator

@bottlewook bottlewook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!

}),

/* ----- refresh token api success ----- */
http.post(`${process.env.NEXT_PUBLIC_BASE_URL}/auth/validToken`, () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 두개로 나누지 않고 조건문으로 분기 처리할 수 있지 않나요?

@@ -24,6 +24,12 @@ export const login = async ({
return response;
};

export const refreshToken = async () => {
const response = await postRequest<RefreshTokenType, null>('/auth/validToken');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 api는 지용님이 만들어주실 예정인가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아마 그러실 것 같아요. 개발 예정이라고 하셨습니다!


import { useMutation } from '@tanstack/react-query';

import useLoggedOut from '@/hooks/useLoggedOut';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import useLoggedOut from '@/hooks/useLoggedOut';
import useLoggedOut from '@hooks/useLoggedOut';

};

const onError = () => {
handleLogout('/login');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

다시 로그인 해주세요 표시를 토스트로 보여줘도 될 것 같네요
하나 만들겠습니다!

@@ -0,0 +1,22 @@
import useRefreshToken from '@remote/queries/auth/useRefreshToken';

const JWT_EXPIRY_TIME = 15 * 60 * 1000;
Copy link
Collaborator

@bottlewook bottlewook Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

서버 토큰 만료 시간이 15분이라 14분으로 맞춰도 될 것 같아요!


useEffect(() => {
if (userId !== null) {
startRefreshTokenInterval();
Copy link
Collaborator

@bottlewook bottlewook Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존에 가지고 있던 토큰을 이용해서 새로운 토큰을 발급 받을 예정이신거죠?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 지용님이랑 얘기해봤는데 헤더 Authentication에 담아 보내주면 body에 새로운 토큰을 넣어서 보내주신다고 하십니다!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 알겠습니다!

Copy link
Collaborator

@bottlewook bottlewook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굳!

@seoye0ng seoye0ng merged commit 8f1ce13 into develop Feb 20, 2024
6 checks passed
@seoye0ng seoye0ng deleted the auth-refresh-token branch February 20, 2024 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feature 기능 개발 🔨 Refactor 코드 리팩토링 ✅ Test test 관련(storybook, jest...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

페이지 기능: 로그인 이후 로그인 만료, 로그인 연장 처리
2 participants